﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace Microsoft.Office.Project.EPMAuditing.Library
{
    public static class CompareHelper
    {
        public static string Date(string fieldName, DateTime oldDate, DateTime newDate)
        {
            if (oldDate != newDate)
                return System.String.Format(CultureInfo.InvariantCulture, @"<change field=""{0}""><oldValue>{1}</oldValue><newValue>{1}</newValue></change>",
                    fieldName,
                    oldDate.ToUniversalTime(),
                    newDate.ToUniversalTime());
            else
                return string.Empty;
        }

        public static string String(string fieldName, string oldString, string newString)
        {
            if (oldString != newString)
                return System.String.Format(CultureInfo.InvariantCulture, @"<change field=""{0}""><oldValue>{1}</oldValue><newValue>{1}</newValue></change>",
                    fieldName,
                    oldString,
                    newString);
            else
                return string.Empty;
        }

        public static string Bool(string fieldName, bool oldBool, bool newBool)
        {
            if (oldBool != newBool)
                return System.String.Format(CultureInfo.InvariantCulture, @"<change field=""{0}""><oldValue>{1}</oldValue><newValue>{1}</newValue></change>",
                    fieldName,
                    oldBool.ToString(),
                    newBool.ToString());
            else
                return string.Empty;
        }

        public static string Int(string fieldName, int oldInt, int newInt)
        {
            if (oldInt != newInt)
                return System.String.Format(CultureInfo.InvariantCulture, @"<change field=""{0}""><oldValue>{1}</oldValue><newValue>{1}</newValue></change>",
                    fieldName,
                    oldInt.ToString(CultureInfo.InvariantCulture),
                    newInt.ToString(CultureInfo.InvariantCulture));
            else
                return string.Empty;
        }

        public static string Short(string fieldName, short oldShort, short newShort)
        {
            if (oldShort != newShort)
                return System.String.Format(CultureInfo.InvariantCulture, @"<change field=""{0}""><oldValue>{1}</oldValue><newValue>{1}</newValue></change>",
                    fieldName,
                    oldShort.ToString(CultureInfo.InvariantCulture),
                    newShort.ToString(CultureInfo.InvariantCulture));
            else
                return string.Empty;
        }

        public static string Double(string fieldName, double oldDouble, double newDouble)
        {
            if (oldDouble != newDouble)
                return System.String.Format(CultureInfo.InvariantCulture, @"<change field=""{0}""><oldValue>{1}</oldValue><newValue>{1}</newValue></change>",
                    fieldName,
                    oldDouble.ToString(CultureInfo.InvariantCulture),
                    newDouble.ToString(CultureInfo.InvariantCulture));
            else
                return string.Empty;
        }

    }
}
